package bitwiseOperation;

//https://leetcode.cn/problems/missing-two-lcci/description/
public class l_interview_1719 {
    public int[] missingTwo(int[] nums) {
        //原数组加上 1--n 就转换成只有两个数字出现一次, 其他数字都出现两次这道题
        int n = nums.length + 2;
        int res = 0;
        int[] ans = new int[2];
        for(int i = 1; i <= n; i++)
            res ^= i;
        for(int x: nums)
            res ^= x;
        int flag = res & (-res);
        for(int i = 1; i <= n; i++)
        {
            if((i & flag) != 0)
                ans[0] ^= i;
            else
                ans[1] ^= i;
        }
        for(int x: nums)
        {
            if((x & flag) != 0)
                ans[0] ^= x;
            else
                ans[1] ^= x;
        }
        return ans;
    }
}
